/**
 * Created by lenovo on 2017/4/28.
 */
(function(){
    //页面的高度
    parent.$('#content').css('height','1000px').css('width','960px');

    //跳转到添加银行卡
    $('.add_card1').on('click',function(){
        parent.$('iframe').attr('src','./html/addCard.html');
    })

    //银行卡删除和默认 鼠标悬停事件
    var bank_list =  $('.bank_list');
    bank_list.on('mouseover','li',function(){
        $(this).find('.setting').css('display','block');
    })
    bank_list.on('mouseout','li',function(){
        $(this).find('.setting').css('display','none');
    })
    $('.bank_list').on('hover','.setting',function(){
        $(this).css('display','block');
    },function(){
        $(this).css('display','none');
    })

    //删除银行卡
    $('.bank_list').on('click','.setting .cancel',function(){
//      $(this).parent().parent().parent().remove();
        var removeId = $(this).parent().parent().parent().attr("data-Id");
        var removeEle = $(this).parent().parent().parent();
        
         $.ajax({
	        url:config.baseUrl+'/settings/deleteBankCard',
	        type:'GET',
	        data:{'id':removeId},
	        dataType:'json',
	        success:function(result){
	        	  console.log('删除成功');
	        	  removeEle.remove();
	        },
	        error:function(result){
	        	 console.log('删除失败');
	        }
         })
      }) 


    //添加的所有的银行卡接口
      $.ajax({
        url:config.baseUrl+'/settings/getClubBankCardList',
        type:'GET',
        data:{'clubId':1},
        dataType:'json',
        success:function(result){
          if(result){
          	  var html = "";
          	  for(var i = 0;i<result.body.length;i++){
          	  	html= '<li data-Id='+result.body[i].id+'><div class="cl_card"><div class="card1">'+
          	  	      '<img class="ca_img" src="" alt="">'+
          	  	      '<div class="ca_div">'+
          	  	      '<span class="span1">'+result.body[i].openBank+'</span>'+
                      '<span class="span2">'+result.body[i].openPlace+'</span>'+
                      '<span class="span3">'+
                      '<span>'+result.body[i].accountNo.substr(0, 4)+'</span><span>'+result.body[i].accountNo.substr(4, 4)+'</span><span>'+result.body[i].accountNo.substr(8, 4)+'</span><span>'+result.body[i].accountNo.substr(12, 4)+'</span>'+
                      '</span></div>'+
                      '</div>'+
                      '<div class="setting"><span class="default">默认</span><span class="cancel">删除</span></div>'+
                      '</div></li>';  
                 $(html).prependTo('.bank_list');     
                 html="";
          	  }
          }
        },
        error:function(result){

        }
    })
})()